﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.IO;

namespace TMS
{
    public partial class CreateEditAgreementControl : UserControl
    {
        public MySqlDataAdapter MyDA = new MySqlDataAdapter();
        bool edit = false;
        int ID = 0;

        public CreateEditAgreementControl()
        {
            InitializeComponent();
            fillPartnersCB();
        }

        public CreateEditAgreementControl(DataGridViewRow parameters)
        {
            InitializeComponent();
            edit = true;

            fillPartnersCB();
        }

        private void fillPartnersCB()
        {
            string connString = ConfigurationManager.ConnectionStrings["MyDBConnectionString"].ConnectionString;

            MySqlConnection mysqlCon = new MySqlConnection(connString);
            mysqlCon.Open();

            string sqlSelectAll = "SELECT * FROM partners";
            MyDA.SelectCommand = new MySqlCommand(sqlSelectAll, mysqlCon);

            DataTable table = new DataTable();
            MyDA.Fill(table);

            //DataRow row = table.NewRow();
            //row["name"] = "<--Изберете кореспондент-->";
            //table.Rows.InsertAt(row, 0);

            cbbPartner.DataSource = table;
            cbbPartner.ValueMember = "id";
            cbbPartner.DisplayMember = "name";

            mysqlCon.Close();
        }

        private void btnChooseFile_Click(object sender, EventArgs e)
        {
            openFileDialog1.InitialDirectory = @"C:\";
            openFileDialog1.Title = "Select a File";

            //openFileDialog1.Filter = "Text Files|*.txt";
            //openFileDialog1.FilterIndex = 1;

            if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
            {
                txtSource.Text = openFileDialog1.FileName;
            }
            else
                txtSource.Text = "";
        }

       
        private void btnSaveAgreement_Click(object sender, EventArgs e)
        {
            string fulllocimage = openFileDialog1.FileName;
            File.Copy(fulllocimage, Path.Combine(@"D:\Work\UploadedFiles\", Path.GetFileName(fulllocimage)));
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            System.Diagnostics.Process.Start(@"D:\Work\UploadedFiles\_DSC3130.jpg");
        }
    }
}
